<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content-header">
    <h1>工艺卡转序-历史接收</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal" onkeydown="if(event.keyCode==13)return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none"
                                     style="margin-left:0px;margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        用户名
                                    </label>
                                    <label class="control-label" th:text="${user.name}">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        部门
                                    </label>
                                    <label class="control-label" th:text="${user.deptName}==null?'':${user.deptName}">
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        车间
                                    </label>
                                    <label class="control-label"
                                           th:text="${user.branchName}==null?'':${user.branchName}">
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label for="prodNo" class="control-label">
                                        生产令号
                                    </label>
                                    <label class="control-label">
                                        <input id="prodNo" class="form-control" name="prodNo" placeholder="请输入生产令号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label for="part" class="control-label">
                                        部分
                                    </label>
                                    <label class="control-label">
                                        <input id="part" class="form-control" name="part" placeholder="请输入部分"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label for="drawNo" class="control-label">
                                        图号
                                    </label>
                                    <label class="control-label">
                                        <input id="drawNo" class="form-control" name="drawNo" placeholder="请输入图号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label for="prodNo" class="control-label">
                                        类型
                                    </label>
                                    <label class="control-label">
                                        <select name="special" class="form-control">
                                            <option value="">请选择</option>
                                            <option value="机械">机械</option>
                                            <option value="流体">流体</option>
                                            <option value="自动化">自动化</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label for="query-startTime" class="control-label">
                                        接收时间
                                    </label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker"
                                           name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                    <div id="noData" class="col-md-12" style="text-align: center;vertical-align: middle;display: none;"><h2>查无记录</h2></div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table;
    let status = ['', '未开始', '执行中', '部分转序', '全部转序'];
    let statusClass = ['', 'label-default', 'label-warning', 'label-success', 'label-success'];
    $(function () {
        loadTableData();
    });

    /**
     * 加载数据
     */
    function loadTableData() {
        $('#bootstrap-table').bootstrapTable('destroy');//这里必须要添加这个销毁，否则新增、修改、查看的切换可编辑列表中的数据可能加载出现问题。
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "transposition/historicalRec/list",
            showColumns: false,
            showExport: false,
            editable: true,//开启编辑模式
            uniqueId: 'id',
            onLoadSuccess:function (data){
                if(data.rows.length===0){
                    $("#noData").show();
                    $("#bootstrap-table").hide();
                }else{
                    $("#noData").hide();
                    $("#bootstrap-table").show();
                }
            },
            columns: [
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '生产令号', field: 'prodNo', width: '110',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'proName',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '类型', field: 'special', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '部分', field: 'part', width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '图号', field: 'drawNo', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '零件名称', field: 'drawName', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '零件数量',
                    field: 'drawNum',
                    width: '90',
                    edit: {type: 'text'},
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '工艺路线', field: 'route', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },

                {
                    title: '申请数量', field: 'num', width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '路线状态', field: 'status', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            //  /** 状态 1=未开始 2=执行中 3=部分转序 4=全部转序 */
                            return '<label class="badge ' + statusClass[value] + '">' + status[value] + '</label>';
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '接收时间', field: 'recTime', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '140',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (hasP('tran:historical:success')) {
                            if (row.status === 3 && row.nextApplyNum === 0) {
                                elements.push('<button class="btn btn-warning btn-xs" onclick="cancelRec(' + row.id + ')">撤销接收</button>');
                            }
                        }
                        return elements.join('');
                    }
                }
            ]
        });
    }

    /** 撤销接收 */
    function cancelRec(id) {
        js.post({
            url: ctx + "transposition/historicalRec/cancel/receive",
            data: {id: id},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        })
    }

</script>
</body>
</html>